﻿using System.Web.Mvc;

namespace JoelAbrahamsson.Web
{
    public class PageDataModelBinder : IModelBinder 
    {
        public PageDataModelBinder()
        {
            CurrentPageResolver = new CurrentPageResolver(); 
        }

        private CurrentPageResolver CurrentPageResolver { get; set; }

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string slug = (string)controllerContext.RouteData.Values["slug"];
            return CurrentPageResolver.GetCurrentPage(slug);
        }
    }
}
